${r'<?xml version="1.0" encoding="UTF-8" ?>'}
${r'<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >'}

${r'<'}mapper namespace="${basePackage}.${mapper}.${className}Mapper">
    <!-- 结果映射关系 -->
    ${r'<'}resultMap id="AllColumnMap" type="${basePackage}.vo.${className}VO">
<#list columns as column>
    <#if (column.attrName == "valid" || column.attrName == "deleted")>
    <#else>
        ${r'<'}result column="${column.columnName}" property="${column.attrName}"/>
    </#if>
</#list>
    ${r'<'}/resultMap>

    <!-- 表字段的sql -->
    ${r'<'}sql id="all_column">
    <#list columns as column>
        <#if (column.attrName == "valid" || column.attrName == "deleted")>
        <#else>
        ${column.columnName}<#if column_has_next>,</#if>
        </#if>
    </#list>
    ${r'<'}/sql>

    <!-- 查询列表 -->
    ${r'<'}select id="select" resultType="${basePackage}.vo.${className}VO">
        SELECT
        <#list columns as column>
            <#if (column.attrName == "valid" || column.attrName == "deleted")>
            <#else>
            t1.${column.columnName}<#if column_has_next>,</#if>
            </#if>
        </#list>
        FROM ${tableName} t1
        ${r'<'}where>
        <#list columns as column>
            <#if (column.attrName == "valid" || column.attrName == "deleted")>
            <#else>
            ${r'<'}if test="pojo.${column.attrName} != null"> AND t1.${column.columnName} = ${r'#'}{pojo.${column.attrName}}${r'<'}/if>
            </#if>
        </#list>
        <#list columns as column>
            <#if (column.attrName == "valid")>
            AND t1.valid = 1
            </#if>
            <#if (column.attrName == "deleted")>
            AND t1.deleted = 0
            </#if>
        </#list>
        ${r'<'}/where>
    ${r'<'}/select>
    <!-- 此处统计总条数为上面的方法附属查询方法，查询条件与上面的务必要一致 -->
    ${r'<'}select id="select_COUNT" resultType="java.lang.Long">
        SELECT
        COUNT(*)
        FROM ${tableName} t1
        ${r'<'}where>
        <#list columns as column>
            <#if (column.attrName == "valid" || column.attrName == "deleted")>
            <#else>
            ${r'<'}if test="pojo.${column.attrName} != null"> AND t1.${column.columnName} = ${r'#'}{pojo.${column.attrName}}${r'<'}/if>
            </#if>
        </#list>
        <#list columns as column>
            <#if (column.attrName == "valid")>
            AND t1.valid = 1
            </#if>
            <#if (column.attrName == "deleted")>
            AND t1.deleted = 0
            </#if>
        </#list>
        ${r'<'}/where>
    ${r'<'}/select>

    <!-- 查询一条记录 -->
    ${r'<'}select id="selectByPk" resultType="${basePackage}.vo.${className}VO">
        SELECT
        <#list columns as column>
            <#if (column.attrName == "valid")>
            <#else>
            t1.${column.columnName}<#if column_has_next>,</#if>
            </#if>
        </#list>
        FROM ${tableName} t1
        ${r'<'}where>
        <#list pkColumns as column>
            <#if column_index == 0>
            t1.${column.columnName} = ${r'#'}{${column.attrName}}
            <#else>
            AND t1.${column.columnName} = ${r'#'}{${column.attrName}}
            </#if>
        </#list>
        <#list columns as column>
            <#if (column.attrName == "valid")>
            AND t1.valid = 1
            </#if>
            <#if (column.attrName == "deleted")>
            AND t1.deleted = 0
            </#if>
        </#list>
        ${r'<'}/where>
    ${r'<'}/select>

${r'<'}/mapper>